package com.diqizu.servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.diqizu.dao.ImgDaoImpl;
import com.diqizu.dao.ChanPinDaoImpl;
import com.diqizu.dao.DisPlayDaoImpl;
import com.diqizu.dao.ProDuctType;
import com.diqizu.entity.Images;
import com.diqizu.entity.ChanPininof;
import com.diqizu.entity.DisPlay;
import com.diqizu.entity.ProType;


/**
 * 鍦板潃锛歭localhost:8080/DiQiZu/ChanPinServlet?method=toDisplay
 * 
 * @author DELL
 *
 */
@WebServlet("/ChanPinServlet")
public class ChanPinServlet extends BaseServlet {
	DisPlayDaoImpl dao = new DisPlayDaoImpl();
	ChanPinDaoImpl dao2 = new ChanPinDaoImpl();
	ProDuctType dao3 = new ProDuctType();
	ImgDaoImpl dao4=new ImgDaoImpl();
//获取所有详情和产品分类列表。头部使用
	public void toDisplay(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ArrayList<DisPlay> Productdetails = dao.displayc(null);//获取所以详情
		ArrayList<ProType> type = dao3.type();//获取产品分类列表
		request.setAttribute("Productdetails", Productdetails);
		request.setAttribute("type", type);
		System.out.println("执行的语句是�" + Productdetails);
		request.getRequestDispatcher("productlist.jsp").forward(request, response);// 跳转
	}

	// 跳转单个物品详情
	public void toDisplay2(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
//单个产品详情
		String id2 = request.getParameter("id");
		int id = Integer.valueOf(id2);
		ArrayList<DisPlay> Productdetails = dao.displayb(id);
		request.setAttribute("Productdetails", Productdetails);
		System.out.println("产品详情是" + Productdetails);
		// 产品图片
		ArrayList<Images> Productdimgs = dao4.imgall(); 
		request.setAttribute("Productdimgs", Productdimgs);
		System.out.println("产品图片是" + Productdimgs);
		ArrayList<ProType> type = dao3.type();//获取产品分类列表
		request.setAttribute("type", type);
		
		request.getRequestDispatcher("productdetails.jsp").forward(request, response);// 跳转到你写的页面，产品页名字
	}

	// 跳转到产品分类
	public void toDisplay3(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
//
		String productTypeId = request.getParameter("productTypeId");
		ArrayList<DisPlay> Productdetails = dao.displayc(productTypeId);//获取单个产品分类
		ArrayList<ProType> type = dao3.type();//获取产品分类列表
		request.setAttribute("Productdetails", Productdetails);
		request.setAttribute("type", type);
		request.setAttribute("获取单个产品分类", Productdetails);
		System.out.println("获取产品分类列表" + type);
		request.getRequestDispatcher("productlist.jsp").forward(request, response);// 璺宠浆鍒颁綘鍐欑殑椤甸潰锛屼骇鍝侀〉鍚嶅瓧
	}
	// 系列方法
	public void toSearch(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	    // 获取参数
	    String productTypeId = request.getParameter("productTypeId");
	    String searchName = request.getParameter("searchName");
	    // productype系列--集合
	    
	    ArrayList<ProType> type = dao3.type();
	    //通过typeId和searchName
	    
	    ArrayList<DisPlay> Productdetails=dao.showSearch(productTypeId,searchName);
	    // 存在作用中
	    // type
	   
	    request.setAttribute("type", type);
	    // 产品列表--把原来的覆盖掉,赋予新的值
	    request.setAttribute("Productdetails", Productdetails);
	    request.getRequestDispatcher("productlist.jsp").forward(request, response);// 璺宠浆
	  }

}